using System;
using System.Collections.Generic;
using System.Text;
using OA.Common;

namespace OA.DAL
{
    /// <summary>
    /// 数据访问类:系统配置
    /// </summary>
    public class SystemConfig
    {
        /// <summary>
        ///  读取系统配置文件
        /// </summary>
        public Model.Config.SystemConfig LoadConfig()
        {
            Model.Config.SystemConfig model = CacheHelper.Get<Model.Config.SystemConfig>(Keys.CacheSystemConfig);
            if (model == null)
            {
                lock (Keys.CacheSystemConfig)
                {
                    if (model == null)
                    {
                        string path = Utils.GetMapPath(Keys.SystemConfigXMLPath);
                        model = (Model.Config.SystemConfig)SerializationHelper.Load(typeof(Model.Config.SystemConfig), path);
                        CacheHelper.Insert(Keys.CacheSystemConfig, model, path);
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 写入系统配置文件
        /// </summary>
        public  Common.Result SaveConifg(Model.Config.SystemConfig model)
        {
            lock (Keys.CacheSystemConfig)
            {
                SerializationHelper.Save(model,Utils.GetMapPath(Keys.SystemConfigXMLPath));
            }
            Common.Result ret = new Result(true, 1, "保存成功");
            return ret;
        }

    }
}
